/*
 * RTSAI - Real-Time Strategy engine for AI research
 * Copyright(C) 2006 DIMAp-UFRN, licensed under LGPL
 *
 * Unit header ( Unit.h )
 * Author: Diogo Leite Reboucas
 */

#ifndef UNIT_H_
#define UNIT_H_

// INCLUDES -------------------------------------------------------------------
#include "OpenSteer/AbstractVehicle.h"
#include "OpenSteer/Obstacle.h"
#include "OpenSteer/Pathway.h"
#include "OpenSteer/SimpleVehicle.h"
#include "OpenSteer/Vec3.h"
#include "Draw.h"
#include "PoolElement.h"
#include "Common.h"
#include "Message.h"

using OpenSteer :: AVGroup;
using OpenSteer :: AbstractVehicle;
using OpenSteer :: Obstacle;
using OpenSteer :: ObstacleGroup;
using OpenSteer :: Pathway;
using OpenSteer :: SimpleVehicle;
using OpenSteer :: Vec3;

// CLASS ----------------------------------------------------------------------
/*! This class implements a unit for the game
 */
class Unit : public PoolElement,
             public ConcreteMessageReceiver,
             public OpenSteer::SimpleVehicle
{
    // PUBLIC METHODS =========================================================
    public:
        // Constructor --------------------------------------------------------
        Unit ();

        // void ---------------------------------------------------------------
        void reset (); // ( PoolElement :: virtual reset () = 0; )
        Action* act ();

        void change_state ( UnitState *new_state );
        UnitState* get_state() { return state; }

        // player -------------------------------------------------------------
        Player* get_player ( ) const { return player; }
        void set_player ( Player* p ) { player = p; }

        // message related methods --------------------------------------------
        int sendMessage ( MessageReceiver *receiver, Message::Performative perf, string content );
        int broadcastMessage ( Message::Performative perf, string content );
        int call_for_proposal ( string content );
        int answer ( Message *msg, Message::Performative perf, string content );

        // Steering behaviors -------------------------------------------------
        bool predictCollision ( const GameObject &obj, const Vec3& force, const float predictionTime );
        Vector3D steerToAvoidObject (float timeToCollision, const GameObject& obj) const;
        Vector3D steerToAvoidObjects (float timeToCollision, const ObjectList& objs) const;

        // Destructor ---------------------------------------------------------
        virtual ~Unit ();


        bool operator== ( const Unit &compared ) const {
            return this == &compared;
        }

    // ATTRIBUTES =============================================================
    private:
        /// Owner of this unit
        Player *player;
        /// Current unit state
        UnitState *state;
};

#endif // UNIT_H_
